package ntd.util.modular.common.controller;

import cn.hutool.core.collection.CollectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import ntd.util.config.common.bo.ResponseBO;
import ntd.util.config.common.controller.BaseMybatisController;
import ntd.util.modular.common.entity.Config;
import ntd.util.modular.common.service.ConfigService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"通用数据-配置管理"})
@RestController
@RequestMapping("/common/config")
public class ConfigController extends BaseMybatisController<Config, ConfigService> {

    @GetMapping("get-val")
    @ApiOperation("根据配置code获取配置值")
    public ResponseBO<String> getValByCode(String code) {
        List<Config> configs = getService().query().eq("code", code).list();
        if (CollectionUtil.isEmpty(configs)) {
            return new ResponseBO<>("");
        }
        return new ResponseBO<>(configs.get(0).getVal());
    }

}
